package proxy;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

public class ProxyFactory {

    private static final RealObject realObject = new RealObject();

    public static Sell getProxy() {
        Object o = Proxy.newProxyInstance(realObject.getClass().getClassLoader(),
                realObject.getClass().getInterfaces(),
                (proxy, method, args) -> {
                    System.out.println("proxy is beginning");
                    return method.invoke(realObject, args);
                });
        return (Sell) o;
    }
}
